<?php
declare(strict_types=1);

use Phinx\Migration\AbstractMigration;

final class CreateStepCategoryMonthReportTable extends AbstractMigration
{
    public function up()
    {
        $this->table('step_category_month_report', ['id' => false, 'primary_key' => ['id'], 'engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci', 'comment' => '环节月度报表'])
            ->addColumn('id', 'integer', ['identity' => true, 'signed' => false, 'limit' => 11, 'comment' => '主键ID'])
            ->addColumn('tenant_id', 'integer', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => '租户id'])
            ->addColumn('project_id', 'integer', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => '项目id'])
            ->addColumn('step_category_id', 'integer', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => '环节id'])
            ->addColumn('month_time', 'integer', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => '月份时间戳'])
            ->addColumn('delivery_unit', 'string', ['null' => false, 'default' => '', 'limit' => 128, 'comment' => '交付统计单位'])
            ->addColumn('step_category_ids', 'string', ['null' => false, 'default' => '', 'limit' => 128, 'comment' => '多环节ids'])
            ->addColumn('plan_delivery', 'integer', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => '计划交付数量'])
            ->addColumn('add_delivery', 'integer', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => '新增交付数量'])
            ->addColumn('delivery', 'integer', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => '交付数量'])
            ->addColumn('delivery_no_repair', 'integer', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => '交付数量（未返修）'])
            ->addColumn('abnormal', 'integer', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => '异常数量'])
            ->addColumn('current_work_order_number', 'integer', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => '环节工单数量'])
            ->addColumn('work_order_number', 'integer', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => '工单数量'])
            ->addColumn('created', 'integer', ['null' => false, 'default' => 0, 'limit' => 11, 'signed' => false, 'comment' => '创建时间',])
            ->addColumn('created_by', 'integer', ['null' => false, 'default' => 0, 'limit' => 11, 'signed' => false, 'comment' => '创建人',])
            ->addColumn('updated', 'integer', ['null' => false, 'default' => 0, 'limit' => 11, 'signed' => false, 'comment' => '更新时间',])
            ->addColumn('updated_by', 'integer', ['null' => false, 'default' => 0, 'limit' => 11, 'signed' => false, 'comment' => '更新人',])
            ->addIndex(['project_id', 'step_category_id'], ['type' => 'normal', 'name' => 'idx_project_step_category'])
            ->addIndex(['project_id', 'month_time'], ['type' => 'normal', 'name' => 'idx_project_month_time'])
            ->save();;
    }

    public function down()
    {
        $this->table('step_category_month_report')->drop()->save();
    }
}
